package com.springboot.demo.controller;


import com.cx.item.common.vo.ResultPageVo;
import com.github.pagehelper.PageInfo;
import com.springboot.demo.model.query.GoodsListQuery;
import com.springboot.demo.model.vo.GoodsDetailsVo;
import com.springboot.demo.model.vo.GoodsListVo;
import com.springboot.demo.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by hwm on 2018/6/20.
 */
@Api(description = "商品api")
@Controller
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @ApiOperation("获取商品详情")
    @RequestMapping(value = "/getGoodsDetails", method = RequestMethod.GET)
    @ResponseBody
    public ResultPageVo<GoodsDetailsVo> getGoodsDetails(Integer goodsId) {

        GoodsDetailsVo detailsVo = goodsService.getGoodsDetails(goodsId);

        return ResultPageVo.success(detailsVo);
    }

    @ApiOperation("商品列表")
    @RequestMapping(value = "/getGoodsList", method = RequestMethod.GET)
    @ResponseBody
    public ResultPageVo<PageInfo<List<GoodsListVo>>> getGoodsList(GoodsListQuery goodsListQuery) {

        PageInfo<List<GoodsListVo>> pageInfo = goodsService.getGoodsList(goodsListQuery);

        return ResultPageVo.success(pageInfo);
    }

}
